﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace BKDict.Data_Access
{
    class DictionAccess
    {
        public string MFile { get; set; }
        public string KFile { get; set; }

        public DictionAccess(string _mfile, string _kfile)
        {
            MFile = _mfile;
            KFile = _kfile;
        }

        //Get list key in KFile
        public IEnumerator<string> getListKey()
        {
            using (StreamReader sr = new StreamReader(KFile))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    yield return line;
                }
            }
        }

        //Get mean of one word
        public string getMean(long offset, int length)
        {
            string mean;
            byte[] temp = new byte[length];
            using (FileStream fs = new FileStream(MFile, FileMode.Open, FileAccess.Read))
            {

                for (int i = 0; i < length; i++, offset++)
                {
                    fs.Seek(offset, SeekOrigin.Begin);//Contro ban dau duoc dua ve dau file
                    temp[i] = (byte)fs.ReadByte();
                }
                mean = System.Text.Encoding.UTF8.GetString(temp, 0, length);
                return mean;
            }
        }


    }
}
